﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using DAL;
using System.Data;

namespace BLL
{
    public class CompetitionService
    {
        CompetitionsDAL competitionDAL = new CompetitionsDAL();

        public void CreateCompetition(BoCompetitions comp)
        {
            competitionDAL.Insert(comp);
        }

        public void UpdateCompetition(BoCompetitions comp)
        {
            competitionDAL.Update(comp);
        }

        public void DeleteCompetition(BoCompetitions competition)
        {
            competitionDAL.Delete(competition.COM_ID);
            new BLL.ContestService().DeleteContestByCompetitionId(competition.COM_ID);
        }
        //public void DeleteCompetitionsByAcademyId(string academyId)
        //{
        //    competitionDAL.DeleteCompetitionsByAcademyId(academyId);
        //}
        public BoCompetitions getCompetition(string id)
        {
            return competitionDAL.GetModel(id);
        }

        public IList<BoCompetitions> getAllCompetitions()
        {
            return competitionDAL.GetAllCompetitions();
        }

        public IList<BoCompetitions> getCompetitionsByAcademy(string academyId)
        {
            return competitionDAL.GetCompetitionsByAcademy(academyId);
        }

        public IList<BoCompetitions> getInnerCompetitions()
        {
            return competitionDAL.GetCompetitionsByType(0);
        }

        public IList<BoCompetitions> getOuterCompetitions()
        {
            return competitionDAL.GetCompetitionsByType(1);
        }

        public IList<BoCompetitions> getInnerCompetitionsByAcademy(string academyId)
        {
            return competitionDAL.GetCompetitionsByTypeAndAcademy(0, academyId);
        }

        public IList<BoCompetitions> getOuterCompetitionsByAcademy(string academyId)
        {
            return competitionDAL.GetCompetitionsByTypeAndAcademy(1, academyId);
        }
        /// <summary>
        /// 根据条件选择前top个
        /// </summary>
        /// <param name="top">前几个</param>
        /// <param name="constr">条件</param>
        /// <returns>返回list对象表</returns>
        public DataTable getAllCompetitions(int top, string constr)
        {
            return competitionDAL.getAllCompetitions(top, constr);
        }

        /// <summary>
        /// 得到分页的数据列表
        /// </summary>
        /// <param name="orderCon">排序条件</param>
        /// <param name="sqlCon">查询条件</param>
        /// <param name="pagesize">每页显示大小</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="records">返回查询到的记录</param>
        /// <returns>返回对象列表</returns>
        public DataTable getPageCompetitions(string sqlCon, string orderCon, int pagesize, int pageIndex, out int records)
        {
            return competitionDAL.getPageCompetitions(sqlCon, orderCon, pagesize, pageIndex, out records);
        }

        /// <summary>
        /// 通过竞赛任务的id来获取竞赛项目的id
        /// </summary>
        /// <param name="Con_Id">竞赛任务的id</param>
        /// <returns>返回竞赛项目的对象</returns>
        public BoCompetitions getCompetitionsByContest(string Con_Id)
        {
            return competitionDAL.getCompetitionsByContest(Con_Id);
        }
    }
}
